﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GPSCrowdSource.DataStructures {

  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /// <summary>
  /// Provides a GPS message object that can be used to transmit and process
  /// gps information internally within our system.
  /// </summary>
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  public partial class GPSMessage : GeoPosition {

    #region Constructors

    /// <summary>
    /// Create a copy
    /// </summary>
    public GPSMessage(GPSMessage inOther) : base(inOther) {
      Source = inOther.Source;
      }

    /// <summary>
    /// Create an empty GPS message
    /// </summary>
    public GPSMessage() : base() {
      Source = "Unknown";
      }

    /// <summary>
    /// Create a GPS message with the lattiude,longitude and altitude.
    /// </summary>
    /// <param name="lat">Latitude in decimal degrees</param>
    /// <param name="lon">Longitude in decimal degrees</param>
    /// <param name="alt">Altitude in feet</param>
    /// <param name="time">Time of signal</param>
    /// <param name="src">Source of this message</param>
    public GPSMessage(DateTime inTime, float lat, float lon, float alt, String src) : base(inTime,lat,lon,alt) {
      Source = src;
      }

    #endregion

    #region Properties

    /// <summary>
    /// Get/Set the date time this message was created. (Time of intercept)
    /// </summary>
    public DateTime Time { get; set; }

    /// <summary>
    /// Get/Set the source of this GPS message.
    /// </summary>
    public String Source { get; set; }

    #endregion
    
    #region Object Overrides

    public override bool Equals(object obj) {
      if(obj == null) return false;
      if(ReferenceEquals(this,obj)) return true;

      GPSMessage other = (GPSMessage)obj;
      return base.Equals((GeoPosition)obj) &&
             other.Source == Source &&
             Time == other.Time;
      }

    public override int GetHashCode() {
      return ToString().GetHashCode();
      }

    public override string ToString() {
      return "" + base.ToString() + "," + Time.ToString();
      }

    #endregion

    #region Operator Overloads

    public static bool operator==(GPSMessage a, GPSMessage b) {
      if( ((Object)a) == null && ((Object)b) == null) return true;
      else if( ((Object)a) == null || ((Object)b) == null) return false;
      return a.Equals(b);
      }

    public static bool operator!=(GPSMessage a, GPSMessage b) {
      return !(a == b);
      }

    #endregion
    }

  }
